package com.hyzh.latte.util;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;

import java.util.HashSet;
import java.util.Set;

/**
 * @author: songkui
 * @date: 2022/3/18 10:34
 */
public class StringKits extends StrUtil {

    public static Set<String> toSet(String str, String regex){
        if (isEmpty(str)){
            return null;
        }
        String[] strings =  str.split(regex);
        Set<String> set = new HashSet<>(MapKits.mapSize(strings.length));
        for (String s : strings){
            set.add(s);
        }
        return set;
    }

//    public static void main(String[] args) {
//        System.out.println(!isChinese(" Adsdfsd"));
//    }

    public static int t(){
        try {
            int a = 1/0;
            return a;
        } catch (Exception e) {
           return 10;
        } finally {
            int c = 1/0;
            System.out.println("xxxxxxxx");
//            return 20;
        }
    }



    public static boolean isChinese(String str) {
        if (isEmpty(str)){
            return false;
        }
        char ch = str.charAt(0);
        Character.UnicodeBlock block = Character.UnicodeBlock.of((int) ch);
        return (block == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS
                || block == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS
                || block == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A
                || block == Character.UnicodeBlock.GENERAL_PUNCTUATION
                || block == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION
                || block == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS);
    }


    public static String timeSToString(long time){
        DateTime dateTime = DateUtil.date(time*1000);
        return dateTime.toString("yyyy-MM-dd HH:mm:ss");
    }



}
